home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / misc / emu / Apex-src.lha / PRHANA.68K < prev    next >
Text File  |  2001-09-30  |  8KB  |  267 lines

  1. ;PRHANA.68K    SEP-01-88    (also see 4 copies of "INFOSTR")
  2. ;All-in-one printer handler for the Amiga.
  3. ;Written by Loren Blaney
  4. ;This is based on PRINTHAN.68K
  5. ;
  6. ;REVISION HISTORY:
  7. ;MAR-09-87, Original.
  8. ;MAY-18-87, Fixed long line wraparound, changed string termination.
  9. ;
  10. ;NOTES:
  11. ;This program is used to produce the following handlers, depending on
  12. ; the conditional assembly flags:
  13. ;    PARHAN, EPSONHAN, ITOHAN, DUMHAN
  14. ;
  15. ;This printer handler paginates and handles tabs. The printer should be
  16. ; configured so that a <CR> moves to the start of the current line, and
  17. ; a <LF> moves down one line.
  18. ;This will print 60 lines per page, with a half-inch margin at the top
  19. ; and bottom. It is assumed that the page is 11 inches long and that
  20. ; there are 6 lines per inch.
  21.  
  22.     NOLIST
  23.     INCLUDE    SYSPAG        ;Get system-page definitions
  24.     LIST
  25.  
  26. ;Select only one of the following by setting it TRUE:
  27. PARHAN    EQU    FALSE        ;Non-specific printer handler
  28. EPSONHAN EQU    FALSE        ;Epson printer handler
  29. ITOHAN    EQU    TRUE        ;C.Itoh printer handler
  30. DUMHAN    EQU    FALSE        ;Direct control, no pagination, etc.
  31.  
  32. DEVNUM    EQU    2        ;Printer device number
  33.  
  34.     IF    EPSONHAN ! ITOHAN
  35. LINESIZ    EQU    96        ;Number of characters on a line
  36.     ELSE
  37. LINESIZ    EQU    80        ;Number of characters on a line
  38.     ENDIF
  39.  
  40. ;I/O ADDRESSES:
  41.  
  42. CIAA    EQU    $BFE001        ;Base address of 8520-A
  43. CIAB    EQU    $BFD000        ;Base address of 8520-B
  44.  
  45. ;Offsets to certain CIAA registers:
  46. PRA    EQU    $000        ;Port register A
  47. PRB    EQU    $100        ;Port register B
  48. DDRA    EQU    $200        ;Data direction register A
  49. DDRB    EQU    $300        ;Data direction register B
  50. SDR    EQU    $C00        ;Serial data register
  51. ICR    EQU    $D00        ;Interrupt control register
  52. CRA    EQU    $E00        ;Control register A
  53. CRB    EQU    $F00        ;Control register B
  54.  
  55.  
  56.     ORG    $7E900
  57. START    EQU    @        ;Address where this handler starts
  58.  
  59. ;=======================================================================
  60. ;PRINTER HANDLER
  61. ;
  62. PRHAN    DC.L    DUMMY        ;0 = OPENI
  63.     DC.L    OPENO        ;1 = OPENO
  64.     DC.L    DUMMY        ;2 = CHIN
  65.     IF    DUMHAN
  66.     DC.L    BYTEOUT        ;3 = BYTEOUT, direct output
  67.     ELSE
  68.     DC.L    CHOUT        ;3 = CHOUT, with paging, tabs, etc.
  69.     ENDIF
  70.     DC.L    CLOSE        ;4 = CLOSE
  71.     DC.L    GETINFO        ;5 = GETINFO
  72.     DC.L    BYTEOUT        ;6 = BYTEOUT, low level output
  73.     DC.L    DUMMY        ;7 = spare
  74.  
  75. HPOSN    DC.B    0        ;Horizontal position counter
  76.                 ; (first column = 0)
  77. LINE    DC.B    0        ;Line counter. Top line = 0
  78.  
  79. ;----------------------------------------------------------------------
  80. ;Open (initialize) buffered terminal for output.
  81. ;
  82. OPENO    MOVE.L    D0,-(SP)    ;Save D0
  83.  
  84.     BSR    OPEN
  85.     IF    EPSONHAN
  86.     MOVEQ    #ESC,D0        ;Set elite mode (96 columns)
  87.     BSR    BYTEOUT
  88.     MOVEQ    #'M',D0
  89.     BSR    BYTEOUT
  90.     ENDIF
  91.  
  92.     IF    ITOHAN
  93.     MOVEQ    #ESC,D0        ;Set elite mode (96 columns)
  94.     BSR    BYTEOUT
  95.     MOVEQ    #'E',D0
  96.     BSR    BYTEOUT
  97.     ENDIF
  98.  
  99.     CLR.B    LINE.L        ;Init line counter to first line
  100.     BSR    DOCR        ;Make sure we're at the start of
  101.                 ; the line
  102.     MOVE.L    (SP)+,D0    ;Restore D0
  103.     RTS
  104.  
  105. ;----------------------------------------------------------------------
  106. ;Output the character in D0 to the printer.
  107. ; Handle some special characters: NUL, TAB, CR, & FF.
  108. ; This does not handle deletes (DEL).
  109. ;
  110. CHOUT    CMPI.B    #$20,D0        ;Is it a control character?
  111.     BHS.S    CHO190        ;Branch if not
  112.  
  113.     CMPI.B    #NUL,D0        ;Is it a null character?
  114.     BNE.S    CHO110        ;Branch if not
  115. DUMMY    RTS            ;Ignore nulls
  116.  
  117. CHO110    CMPI.B    #TAB,D0        ;Is it a tab character?
  118.     BNE.S    CHO120        ;Branch if not
  119.     BRA    DOTAB        ;(PBRA) Do tab and return
  120.  
  121. CHO120    CMPI.B    #CR,D0        ;Is it a carriage return?
  122.     BNE.S    CHO130        ;Branch if not
  123.     BRA    NEWLIN        ;(PBRA) Start a new line and return
  124.  
  125. CHO130    CMPI.B    #FF,D0        ;Is it a form feed?
  126.     BNE.S    CHO140        ;Branch if not
  127.     BRA    NEWPAG        ;(PBRA) Do page eject and return
  128.  
  129. CHO140    CMPI.B    #BS,D0        ;Is it a backspace?
  130.     BNE.S    CHO190        ;Branch if not
  131.     SUBQ.B    #1,HPOSN.L    ;Decrement X position
  132.     BRA    BYTEOUT        ;(PBRA) Output the character and return
  133.  
  134. CHO190    CMPI.B    #LINESIZ,HPOSN.L ;Are we at the end of the line +1?
  135.     BLO.S    CHO195        ;Branch if not
  136.     BSR    DOCRLF        ;Start a new line
  137. CHO195    ADDQ.B    #1,HPOSN.L    ;Bump X position
  138.     BRA    BYTEOUT        ;(PBRA) Output the character and return
  139.  
  140. ;----------------------------------------------------------------------
  141. ;Close the printer.
  142. ;
  143. CLOSE    BRA    NEWPAG        ;(PBRA) Eject page and return
  144.  
  145. ;----------------------------------------------------------------------
  146. ;Return the address of the information array in D0.
  147. ;
  148. GETINFO    MOVE.L    #INFO,D0
  149.     RTS
  150.  
  151. INFO    DC.L    START        ;Starting and ending addresses of this
  152.     DC.L    END        ; handler
  153.     DC.L    INFOSTR        ;Description
  154.  
  155.     IF    EPSONHAN
  156. INFOSTR    ASCII    'EPSONHAN  SEP-01-88  96-column Epson printer'
  157.     DC.B    0
  158.     ENDIF
  159.  
  160.     IF    ITOHAN
  161. INFOSTR    ASCII    'ITOHAN    SEP-01-88  96-column C.Itoh printer'
  162.     DC.B    0
  163.     ENDIF
  164.  
  165.     IF    PARHAN
  166. INFOSTR    ASCII    'PARHAN    SEP-01-88  80-column Generic printer'
  167.     DC.B    0
  168.     ENDIF
  169.  
  170.     IF    DUMHAN
  171. INFOSTR    ASCII    'DUMHAN    SEP-01-88  Direct control of printer'
  172.     DC.B    0
  173.     ENDIF
  174.  
  175. ;----------------------------------------------------------------------
  176. ;Space over to the next tab stop.
  177. ;
  178. DOTAB    MOVE.L    D0,-(SP)    ;Save D0
  179. DOTAB10    MOVEQ    #SPACE,D0    ;Output a space character
  180.     BSR    BYTEOUT
  181.  
  182.     ADDQ.B    #1,HPOSN.L    ;Bump X position
  183.     CMPI.B    #LINESIZ,HPOSN.L ;Are we at the end of the line +1?
  184.     BLO.S    DOTAB20        ;Branch if not
  185.     BSR    DOCRLF        ;Start a new line
  186.  
  187. DOTAB20    MOVE.B    HPOSN.L,D0    ;Are we at the next tab stop?
  188.     ANDI.B    #$07,D0
  189.     BNE.S    DOTAB10        ;Branch if not
  190.     MOVE.L    (SP)+,D0    ;Restore D0
  191.     RTS
  192.  
  193. ;----------------------------------------------------------------------
  194. ;Move to the next line.
  195. ; Check for end-of-page.
  196. ;
  197. NEWLIN    BSR.S    DOCRLF        ;Move down a line
  198.     CMPI.B    #60,LINE.L
  199.     BLO.S    NL90        ;Branch if we are (we scroll)
  200.     BSR.S    NEWPAG
  201. NL90    RTS
  202.  
  203. ;----------------------------------------------------------------------
  204. ;Advance to the beginning of the next page (form feed).
  205. ;
  206. NEWPAG    BSR.S    DOCR        ;Make sure we're in the left column
  207. NP10    BSR.S    DOLF        ;Move down a line until we're at the
  208.     CMPI.B    #66,LINE.L    ; top of the next page
  209.     BLO.S    NP10        ;6 lines per inch * 11 inches
  210.     CLR.B    LINE.L        ; = 66 lines.  Reset line counter
  211.     RTS
  212.  
  213. ;----------------------------------------------------------------------
  214. ;Advance to the beginning of the next line.
  215. ;
  216. DOCRLF    BSR.S    DOCR        ;Output a carriage return & a line feed
  217.     BRA.S    DOLF        ;(PBRA)
  218.  
  219. ;----------------------------------------------------------------------
  220. ;Output a carriage return.
  221. ;
  222. DOCR    MOVE.L    D0,-(SP)    ;Save D0
  223.     MOVEQ    #CR,D0        ;Output a carriage return
  224.     BSR.S    BYTEOUT
  225.     CLR.B    HPOSN.L        ;Reset horizontal position to 0
  226.     MOVE.L    (SP)+,D0    ;Restore D0
  227.     RTS
  228.  
  229. ;----------------------------------------------------------------------
  230. ;Output a line feed.
  231. ;
  232. DOLF    MOVE.L    D0,-(SP)    ;Save D0
  233.     MOVEQ    #LF,D0        ;Output a line feed
  234.     BSR.S    BYTEOUT
  235.     ADDQ.B    #1,LINE.L    ;Count this line
  236.     MOVE.L    (SP)+,D0    ;Restore D0
  237.     RTS
  238.  
  239. ;======================================================================
  240. ;Initialize data direction registers.
  241. ;
  242. OPEN    MOVE.B    #$FF,DDRB+CIAA.L ;Set outputs for Centronics interface
  243.     MOVE.B    #$C0,DDRA+CIAB.L ;Set for Centronics interface
  244.     RTS
  245.  
  246. ;----------------------------------------------------------------------
  247. ;Low-level routine to output the byte in D0 to the printer.
  248. ; Warning: The Amiga does a fast hardware strobe 3 cycles, about
  249. ; 500 ns, after the data is sent out. The printer is speced at 1 us.
  250. ;
  251. BYTEOUT
  252. BO10    BTST    #0,PRA+CIAB.L    ;Wait until not BUSY
  253.     BNE.S    BO10        ; i.e until bit 0 is low
  254.  
  255.     MOVE.B    D0,PRB+CIAA.L    ;Output byte in D0
  256.     RTS            ; (Strobe handshake is automatic)
  257.  
  258. END    EQU    @-1        ;Address where this handler ends
  259.  
  260. ;----------------------------------------------------------------------
  261. ;Hook this handler into the device-handler table.
  262. ;
  263.     ORG    4 *DEVNUM +DEVTBL
  264.     DC.L    PRHAN
  265.  
  266.     END
  267. -----